package com.lebang.controller.sys;

import com.lebang.aop.ConfigRecord;
import com.lebang.common.Login;
import com.lebang.component.RedisClient;
import com.lebang.entity.MemberVideoCheck;
import com.lebang.service.sys.MemberVideoService;
import com.lebangweb.response.Callback;
import com.lebangweb.response.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import static com.lebang.model.RedisKey.SYS_SETTING;

/**
 * @Author: hwq
 * @Date: 2019/10/28 11:32
 * @Version 1.0
 */
@RequestMapping("/sys/videocheck")
@Controller
public class MemberVideoCheckController {
    @Autowired
    private MemberVideoService memberVideoService;
    @Autowired
    private RedisClient redisClient;
    @Login
    @GetMapping("/list")
    public String list(){
        return "/sys/videocheck/list";
    }
    @Login
    @GetMapping("/edit")
    public String edit(MemberVideoCheck vo, Model model){
        if (vo.getId() != null) {
            vo = memberVideoService.selectById(vo.getId());
        } else {
            vo=new MemberVideoCheck();
        }
        model.addAttribute("item", vo);
        return "/sys/videocheck/edit";
    }

    @Login
    @PostMapping("/edit")
    @ResponseBody
    @ConfigRecord
    public JsonData edit(MemberVideoCheck vo){
        int i=0;
        if (vo.getId() != null) {
            i = memberVideoService.updateVo(vo);
        } else {
            i = memberVideoService.insertVo(vo);
        }
        if (i > 0) {
            redisClient.del(SYS_SETTING);
            return Callback.success("success", "操作成功", null);
        } else {
            return Callback.fail("fail", "操作失败", null);
        }
    }
}
